package com.just.sx.demo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author xiao.shu
 * @date on 2020/11/24 17:57
 * @description
 * @Copyright (c)
 */
public class ThreadPoolExecutorDemo {

    public static void main(String[] args) {

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1L,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 10; i++) {
            Runnable myRunnable = new MyRunnable("" + i);
            threadPoolExecutor.execute(myRunnable);
        }

        threadPoolExecutor.shutdown();
        while (!threadPoolExecutor.isTerminated()){
            System.out.println("Finish all thread!");
        }
    }
}
